#include <rtthread.h>
#include "fal.h"

#ifdef RT_USING_DFS
#include <dfs_fs.h>

int mnt_init(void)
{
    if (dfs_mount("W25Q256", "/", "elm", 0, 0) == 0)
    {
        rt_kprintf("W25Q256 mount successful!\n");
    }
    else
    {
        rt_kprintf("W25Q256 mount failed!\n");
    }

    return 0;
}
//INIT_ENV_EXPORT(mnt_init);



#define FS_PARTITION_NAME   "flash0"
#define OTA_PARTITION_NAME  "download"

int mnt_lfs_int(void)
{
	  fal_init();
		
    struct rt_device *flash_dev = fal_mtd_nor_device_create(FS_PARTITION_NAME);
 
    if (flash_dev == NULL)
    {
        rt_kprintf("Can't create a mtd device on '%s' partition.\n", FS_PARTITION_NAME);
    }
    else
    {
        rt_kprintf("Create a mtd device on the %s partition of flash successful.\n", FS_PARTITION_NAME);
    }
 
    if(rt_device_find(FS_PARTITION_NAME) != RT_NULL)
    {
        if (dfs_mount(FS_PARTITION_NAME, "/", "lfs", 0, 0) == RT_EOK)
        {
                rt_kprintf("onchip lfs filesystem mount to '/' ok\n");
        }
        else
        {
                rt_kprintf("onchip lfs filesystem mount to '/' failed!\n");
                dfs_mkfs("lfs", FS_PARTITION_NAME);
								rt_thread_mdelay(1000);
								rt_hw_cpu_reset();
        }
    }
    else
    {
        rt_kprintf("find filesystem portion failed\r\n");
    }

		return 0;
}
//INIT_ENV_EXPORT(mnt_lfs_int);

#endif
